home *** CD-ROM | disk | FTP | other *** search
/ Super Shareware Collection / Super Shareware Collection.iso / os_2 / memsz220.zip / ITEMS.CPP < prev    next >
Text File  |  1994-02-07  |  15KB  |  787 lines

  1. /******************************************************************* ITEMS.CC
  2.  *                                        *
  3.  *               Display Item Class Functions                *
  4.  *                                        *
  5.  ****************************************************************************/
  6.  
  7. #define INCL_BASE
  8. #define INCL_PM
  9. #include <os2.h>
  10.  
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <string.h>
  14.  
  15. #include "debug.h"
  16. #include "support.h"
  17. #include "restring.h"
  18.  
  19. #include "items.h"
  20.  
  21.  
  22. VOID Item::Paint
  23. (
  24.   HPS hPS,
  25.   RECTL &Rectangle,
  26.   COLOR TextColor,
  27.   COLOR BackColor,
  28.   PSZ Text,
  29.   ULONG NewValue
  30. )
  31. {
  32.   WinDrawText ( hPS, strlen(PCHAR(Text)), Text, &Rectangle,
  33.     TextColor, BackColor, DT_RIGHT | DT_BOTTOM | DT_ERASERECT ) ;
  34.  
  35.   WinDrawText ( hPS, strlen(PCHAR(Label)), Label, &Rectangle,
  36.     TextColor, BackColor, DT_LEFT | DT_BOTTOM ) ;
  37.  
  38.   Value = NewValue ;
  39. }
  40.  
  41.  
  42. ULONG Clock::NewValue ( void )
  43. {
  44.   DATETIME DateTime ;
  45.   DosGetDateTime ( &DateTime ) ;
  46.  
  47.   ULONG Time ;
  48.   Time    = DateTime.weekday ;
  49.   Time *= 100 ;
  50.   Time += DateTime.month ;
  51.   Time *= 100 ;
  52.   Time += DateTime.day ;
  53.   Time *= 100 ;
  54.   Time += DateTime.hours ;
  55.   Time *= 100 ;
  56.   Time += DateTime.minutes ;
  57.  
  58.   return ( Time ) ;
  59. }
  60.  
  61.  
  62. VOID Clock::Repaint
  63. (
  64.   HPS hPS,
  65.   RECTL &Rectangle,
  66.   COLOR TextColor,
  67.   COLOR BackColor,
  68.   BOOL Mandatory
  69. )
  70. {
  71.   ULONG Time = NewValue ( ) ;
  72.  
  73.   if ( Mandatory || ( Time != Value ) )
  74.   {
  75.     BYTE Text [100] ;
  76.     ULONG Dow     = ( Time % 1000000000L ) / 100000000L ;
  77.     ULONG Month  = ( Time % 100000000L )  / 1000000L ;
  78.     ULONG Day     = ( Time % 1000000L )      / 10000L ;
  79.     ULONG Hour     = ( Time % 10000L )      / 100L ;
  80.     ULONG Minute = ( Time % 100L ) ;
  81.  
  82.     sprintf ( PCHAR(Text), "%0.3s, ", DaysOfWeek->Ptr() + Dow*3 ) ;
  83.  
  84.     switch ( CountryInfo.fsDateFmt )
  85.     {
  86.       case DATEFMT_DD_MM_YY:
  87.     sprintf ( PCHAR(Text)+strlen(PCHAR(Text)), "%02lu%s%02lu ",
  88.       Day, CountryInfo.szDateSeparator, Month ) ;
  89.     break ;
  90.  
  91.       case DATEFMT_YY_MM_DD:
  92.       case DATEFMT_MM_DD_YY:
  93.       default:
  94.     sprintf ( PCHAR(Text)+strlen(PCHAR(Text)), "%02lu%s%02lu ",
  95.       Month, CountryInfo.szDateSeparator, Day ) ;
  96.     break ;
  97.     }
  98.  
  99.     if ( CountryInfo.fsTimeFmt )
  100.     {
  101.       sprintf ( PCHAR(Text)+strlen(PCHAR(Text)), "%02lu%s%02lu",
  102.     Hour,
  103.     CountryInfo.szTimeSeparator,
  104.     Minute ) ;
  105.     }
  106.     else
  107.     {
  108.       PCHAR AmPm ;
  109.  
  110.       if ( Hour )
  111.       {
  112.     if ( Hour < 12 )
  113.     {
  114.       AmPm = "a" ;
  115.     }
  116.     else if ( Hour == 12 )
  117.     {
  118.       if ( Minute )
  119.         AmPm = "p" ;
  120.       else
  121.         AmPm = "a" ;
  122.     }
  123.     else if ( Hour > 12 )
  124.     {
  125.       Hour -= 12 ;
  126.       AmPm = "p" ;
  127.     }
  128.       }
  129.       else
  130.       {
  131.     Hour = 12 ;
  132.     if ( Minute )
  133.       AmPm = "a" ;
  134.     else
  135.       AmPm = "p" ;
  136.       }
  137.       sprintf ( PCHAR(Text)+strlen(PCHAR(Text)), "%02lu%s%02lu%s",
  138.     Hour, CountryInfo.szTimeSeparator, Minute, AmPm ) ;
  139.     }
  140.  
  141.     Paint ( hPS, Rectangle, TextColor, BackColor, Text, Time ) ;
  142.   }
  143. }
  144.  
  145.  
  146. ULONG ElapsedTime::NewValue ( void )
  147. {
  148.   ULONG Milliseconds ;
  149.   DosQuerySysInfo ( QSV_MS_COUNT, QSV_MS_COUNT, &Milliseconds, sizeof(Milliseconds) ) ;
  150.   return ( Milliseconds / 60000L ) ;
  151. }
  152.  
  153.  
  154. VOID ElapsedTime::Repaint
  155. (
  156.   HPS hPS,
  157.   RECTL &Rectangle,
  158.   COLOR TextColor,
  159.   COLOR BackColor,
  160.   BOOL Mandatory
  161. )
  162. {
  163.   ULONG Time = NewValue ( ) ;
  164.  
  165.   if ( Mandatory || ( Time != Value ) )
  166.   {
  167.     BYTE Text [100] ;
  168.  
  169.     memset ( Text, 0, sizeof(Text) ) ;
  170.  
  171.     ULONG NumberOfDays = Time / ( 60L * 24L ) ;
  172.  
  173.     if ( NumberOfDays )
  174.     {
  175.       sprintf ( PCHAR(Text), "%lu %s, ",
  176.     NumberOfDays, NumberOfDays > 1 ? Days->Ptr() : Day->Ptr() ) ;
  177.     }
  178.  
  179.     ULONG Minutes = Time % ( 60L * 24L ) ;
  180.  
  181.     sprintf ( PCHAR(Text+strlen(PCHAR(Text))), "%lu%s%02lu",
  182.       Minutes/60, CountryInfo.szTimeSeparator, Minutes%60 ) ;
  183.  
  184.     Paint ( hPS, Rectangle, TextColor, BackColor, Text, Time ) ;
  185.   }
  186. }
  187.  
  188.  
  189. ULONG MemoryFree::NewValue ( void )
  190. {
  191.   ULONG VirtualMemory ;
  192.   DosQuerySysInfo ( QSV_TOTAVAILMEM, QSV_TOTAVAILMEM, &VirtualMemory, sizeof(VirtualMemory) ) ;
  193.  
  194.   ULONG SwapDiskFree = SwapFree->NewValue ( ) ;
  195.  
  196.   LONG Space = LONG(VirtualMemory) - LONG(SwapDiskFree) ;
  197.  
  198.   while ( Space < 0 )
  199.   {
  200.     Space += 0x100000 ;
  201.   }
  202.  
  203.   return ( ULONG(Space) ) ;
  204. }
  205.  
  206.  
  207. VOID MemoryFree::Repaint
  208. (
  209.   HPS hPS,
  210.   RECTL &Rectangle,
  211.   COLOR TextColor,
  212.   COLOR BackColor,
  213.   BOOL Mandatory
  214. )
  215. {
  216.   ULONG Size = NewValue ( ) ;
  217.  
  218.   if ( Mandatory || ( Size != Value ) )
  219.   {
  220.     BYTE Text [100] ;
  221.  
  222.     if ( Size < 0x80000 )
  223.       sprintf ( (PCHAR)Text, "%lu", Size ) ;
  224.     else
  225.       sprintf ( (PCHAR)Text, "%lu", (Size+512)/1024 ) ;
  226.  
  227.     {
  228.       PBYTE p1, p2 ;
  229.       BYTE Work[100] ;
  230.  
  231.       p1 = Text ;
  232.       p2 = Work ;
  233.       while ( *p1 )
  234.       {
  235.     *p2 = *p1 ;
  236.     p1 ++ ;
  237.     p2 ++ ;
  238.     if ( *p1 )
  239.     {
  240.       if ( strlen((PCHAR)p1) % 3 == 0 )
  241.       {
  242.         *p2 = CountryInfo.szThousandsSeparator [0] ;
  243.         p2 ++ ;
  244.       }
  245.     }
  246.       }
  247.       *p2 = 0 ;
  248.       strcpy ( (PCHAR)Text, (PCHAR)Work ) ;
  249.     }
  250.  
  251.     Text[strlen(PCHAR(Text))+1] = 0 ;
  252.     if ( Size < 0x80000 )
  253.       Text[strlen((PCHAR)Text)] = ' ' ;
  254.     else
  255.       Text[strlen((PCHAR)Text)] = 'K' ;
  256.  
  257.     Paint ( hPS, Rectangle, TextColor, BackColor, Text, Size ) ;
  258.   }
  259. }
  260.  
  261.  
  262. ULONG SwapSize::NewValue ( void )
  263. {
  264.   char Path [_MAX_PATH+1] ;
  265.  
  266.   strcpy ( Path, (PCHAR)SwapPath ) ;
  267.  
  268.   if ( Path[strlen(Path)-1] != '\\' )
  269.   {
  270.     strcat ( Path, "\\" ) ;
  271.   }
  272.  
  273.   strcat ( Path, "SWAPPER.DAT" ) ;
  274.  
  275.   ULONG SwapSize = 0 ;
  276.   FILESTATUS3 Status ;
  277.   if ( DosQueryPathInfo ( (PSZ)Path, FIL_STANDARD, &Status, sizeof(Status) ) == 0 )
  278.   {
  279.     SwapSize = Status.cbFileAlloc ;
  280.   }
  281.  
  282.   return ( SwapSize ) ;
  283. }
  284.  
  285.  
  286. VOID SwapSize::Repaint
  287. (
  288.   HPS hPS,
  289.   RECTL &Rectangle,
  290.   COLOR TextColor,
  291.   COLOR BackColor,
  292.   BOOL Mandatory
  293. )
  294. {
  295.   ULONG Size = NewValue ( ) ;
  296.  
  297.   if ( Mandatory || ( Size != Value ) )
  298.   {
  299.     BYTE Text [100] ;
  300.  
  301.     if ( Size < 0x80000 )
  302.       sprintf ( (PCHAR)Text, "%lu", Size ) ;
  303.     else
  304.       sprintf ( (PCHAR)Text, "%lu", (Size+512)/1024 ) ;
  305.  
  306.     {
  307.       PBYTE p1, p2 ;
  308.       BYTE Work[100] ;
  309.  
  310.       p1 = Text ;
  311.       p2 = Work ;
  312.       while ( *p1 )
  313.       {
  314.     *p2 = *p1 ;
  315.     p1 ++ ;
  316.     p2 ++ ;
  317.     if ( *p1 )
  318.     {
  319.       if ( strlen((PCHAR)p1) % 3 == 0 )
  320.       {
  321.         *p2 = CountryInfo.szThousandsSeparator [0] ;
  322.         p2 ++ ;
  323.       }
  324.     }
  325.       }
  326.       *p2 = 0 ;
  327.       strcpy ( (PCHAR)Text, (PCHAR)Work ) ;
  328.     }
  329.  
  330.     Text[strlen(PCHAR(Text))+1] = 0 ;
  331.     if ( Size < 0x80000 )
  332.       Text[strlen((PCHAR)Text)] = ' ' ;
  333.     else
  334.       Text[strlen((PCHAR)Text)] = 'K' ;
  335.  
  336.     Paint ( hPS, Rectangle, TextColor, BackColor, Text, Size ) ;
  337.   }
  338. }
  339.  
  340.  
  341. ULONG SwapFree::NewValue ( void )
  342. {
  343.   char Path [_MAX_PATH+1] ;
  344.  
  345.   strcpy ( Path, (PCHAR)SwapPath ) ;
  346.   strcat ( Path, "\\SWAPPER.DAT" ) ;
  347.  
  348.   ULONG SwapFree = 0 ;
  349.   if ( Path[0] )
  350.   {
  351.     DosError ( FERR_DISABLEHARDERR ) ;
  352.     FSALLOCATE Allocation ;
  353.     DosQueryFSInfo ( Path[0]-'A'+1, FSIL_ALLOC,
  354.       (PBYTE)&Allocation, sizeof(Allocation) ) ;
  355.     DosError ( FERR_ENABLEHARDERR ) ;
  356.  
  357.     SwapFree = Allocation.cUnitAvail*Allocation.cSectorUnit*Allocation.cbSector ;
  358.   }
  359.  
  360.   if ( SwapFree < ULONG(MinFree*1024L) )
  361.     return ( 0L ) ;
  362.   else
  363.     return ( SwapFree - ULONG(MinFree*1024L) ) ;
  364. }
  365.  
  366.  
  367. VOID SwapFree::Repaint
  368. (
  369.   HPS hPS,
  370.   RECTL &Rectangle,
  371.   COLOR TextColor,
  372.   COLOR BackColor,
  373.   BOOL Mandatory
  374. )
  375. {
  376.   ULONG Size = NewValue ( ) ;
  377.  
  378.   if ( Mandatory || ( Size != Value ) )
  379.   {
  380.     BYTE Text [100] ;
  381.  
  382.     if ( Size < 0x80000 )
  383.       sprintf ( (PCHAR)Text, "%lu", Size ) ;
  384.     else
  385.       sprintf ( (PCHAR)Text, "%lu", (Size+512)/1024 ) ;
  386.  
  387.     {
  388.       PBYTE p1, p2 ;
  389.       BYTE Work[100] ;
  390.  
  391.       p1 = Text ;
  392.       p2 = Work ;
  393.       while ( *p1 )
  394.       {
  395.     *p2 = *p1 ;
  396.     p1 ++ ;
  397.     p2 ++ ;
  398.     if ( *p1 )
  399.     {
  400.       if ( strlen((PCHAR)p1) % 3 == 0 )
  401.       {
  402.         *p2 = CountryInfo.szThousandsSeparator [0] ;
  403.         p2 ++ ;
  404.       }
  405.     }
  406.       }
  407.       *p2 = 0 ;
  408.       strcpy ( (PCHAR)Text, (PCHAR)Work ) ;
  409.     }
  410.  
  411.     Text[strlen(PCHAR(Text))+1] = 0 ;
  412.     if ( Size < 0x80000 )
  413.       Text[strlen((PCHAR)Text)] = ' ' ;
  414.     else
  415.       Text[strlen((PCHAR)Text)] = 'K' ;
  416.  
  417.     Paint ( hPS, Rectangle, TextColor, BackColor, Text, Size ) ;
  418.   }
  419. }
  420.  
  421.  
  422. ULONG SpoolSize::NewValue ( void )
  423. {
  424.   ULONG PathSize ;
  425.   DosQuerySysInfo ( QSV_MAX_PATH_LENGTH, QSV_MAX_PATH_LENGTH, &PathSize, sizeof(PathSize) ) ;
  426.  
  427.   PBYTE Path = PBYTE ( malloc ( PathSize ) ) ;
  428.   if ( Path == NULL )
  429.   {
  430. //  Log ( "ERROR: Unable to allocate memory for spool-file search path.\r\n" ) ;
  431.     return ( 0 ) ;
  432.   }
  433.  
  434.   PFILEFINDBUF3 Found = PFILEFINDBUF3 ( malloc ( PathSize + sizeof(FILEFINDBUF3) ) ) ;
  435.   if ( Found == NULL )
  436.   {
  437. //  Log ( "ERROR: Unable to allocate memory for spool-file search result structure.\r\n" ) ;
  438.     free ( Path ) ;
  439.     return ( 0 ) ;
  440.   }
  441.  
  442.   strcpy ( (PCHAR)Path, (PCHAR)SpoolPath ) ;
  443.   strcat ( (PCHAR)Path, "\\*.*" ) ;
  444.  
  445.   HDIR hDir = (HDIR) HDIR_CREATE ;
  446.   ULONG Count = 1 ;
  447.   ULONG TotalSize = 0 ;
  448.  
  449.   if ( !DosFindFirst2 ( Path, &hDir,
  450.     FILE_NORMAL | FILE_READONLY | FILE_DIRECTORY | FILE_ARCHIVED,
  451.     Found, PathSize+sizeof(FILEFINDBUF3), &Count, FIL_STANDARD ) )
  452.   {
  453.  
  454.     do
  455.     {
  456.  
  457.       if ( !strcmp ( (PCHAR)Found->achName, "." )
  458.     OR !strcmp ( (PCHAR)Found->achName, ".." ) )
  459.       {
  460.     continue ;
  461.       }
  462.  
  463.       if ( Found->attrFile & FILE_DIRECTORY )
  464.       {
  465.     HDIR hDir = (HDIR) HDIR_CREATE ;
  466.  
  467.     strcpy ( (PCHAR)Path, (PCHAR)SpoolPath ) ;
  468.     strcat ( (PCHAR)Path, "\\" ) ;
  469.     strcat ( (PCHAR)Path, (PCHAR)Found->achName ) ;
  470.     strcat ( (PCHAR)Path, "\\*.*" ) ;
  471.  
  472.     Count = 1 ;
  473.     if ( !DosFindFirst2 ( Path, &hDir,
  474.       FILE_NORMAL | FILE_READONLY | FILE_ARCHIVED,
  475.       Found, PathSize+sizeof(FILEFINDBUF3), &Count, FIL_STANDARD ) )
  476.     {
  477.       do
  478.       {
  479.         TotalSize += Found->cbFileAlloc ;
  480.       }
  481.       while ( !DosFindNext ( hDir, Found, PathSize+sizeof(FILEFINDBUF3), &Count ) ) ;
  482.       DosFindClose ( hDir ) ;
  483.     }
  484.  
  485.     Count = 1 ;
  486.       }
  487.  
  488.       else
  489.       {
  490.     TotalSize += Found->cbFileAlloc ;
  491.       }
  492.     }
  493.     while ( !DosFindNext ( hDir, Found, PathSize+sizeof(FILEFINDBUF3), &Count ) ) ;
  494.  
  495.     DosFindClose ( hDir ) ;
  496.   }
  497.  
  498.   free ( Path ) ;
  499.   free ( Found ) ;
  500.  
  501.   return ( TotalSize ) ;
  502. }
  503.  
  504.  
  505. VOID SpoolSize::Repaint
  506. (
  507.   HPS hPS,
  508.   RECTL &Rectangle,
  509.   COLOR TextColor,
  510.   COLOR BackColor,
  511.   BOOL Mandatory
  512. )
  513. {
  514.   ULONG Size = NewValue ( ) ;
  515.  
  516.   if ( Mandatory || ( Size != Value ) )
  517.   {
  518.     BYTE Text [100] ;
  519.  
  520.     if ( Size < 0x80000 )
  521.       sprintf ( (PCHAR)Text, "%lu", Size ) ;
  522.     else
  523.       sprintf ( (PCHAR)Text, "%lu", (Size+512)/1024 ) ;
  524.  
  525.     {
  526.       PBYTE p1, p2 ;
  527.       BYTE Work[100] ;
  528.  
  529.       p1 = Text ;
  530.       p2 = Work ;
  531.       while ( *p1 )
  532.       {
  533.     *p2 = *p1 ;
  534.     p1 ++ ;
  535.     p2 ++ ;
  536.     if ( *p1 )
  537.     {
  538.       if ( strlen((PCHAR)p1) % 3 == 0 )
  539.       {
  540.         *p2 = CountryInfo.szThousandsSeparator [0] ;
  541.         p2 ++ ;
  542.       }
  543.     }
  544.       }
  545.       *p2 = 0 ;
  546.       strcpy ( (PCHAR)Text, (PCHAR)Work ) ;
  547.     }
  548.  
  549.     Text[strlen(PCHAR(Text))+1] = 0 ;
  550.     if ( Size < 0x80000 )
  551.       Text[strlen((PCHAR)Text)] = ' ' ;
  552.     else
  553.       Text[strlen((PCHAR)Text)] = 'K' ;
  554.  
  555.     Paint ( hPS, Rectangle, TextColor, BackColor, Text, Size ) ;
  556.   }
  557. }
  558.  
  559.  
  560. ULONG CpuLoad::NewValue ( void )
  561. {
  562.   MaxCount = (ULONG) max ( MaxCount, *IdleCount ) ;
  563.  
  564.   ULONG Load = ( ( MaxCount - *IdleCount ) * 100 ) / MaxCount ;
  565.  
  566.   return ( Load ) ;
  567. }
  568.  
  569.  
  570. VOID CpuLoad::Repaint
  571. (
  572.   HPS hPS,
  573.   RECTL &Rectangle,
  574.   COLOR TextColor,
  575.   COLOR BackColor,
  576.   BOOL Mandatory
  577. )
  578. {
  579.   ULONG Load = NewValue ( ) ;
  580.  
  581.   if ( Mandatory || ( Load != Value ) )
  582.   {
  583.     BYTE Text [100] ;
  584.     sprintf ( (PCHAR)Text, "%lu%%", Load ) ;
  585.     Paint ( hPS, Rectangle, TextColor, BackColor, Text, Load ) ;
  586.   }
  587. }
  588.  
  589.  
  590. ULONG TaskCount::NewValue ( void )
  591. {
  592.   return ( WinQuerySwitchList ( Anchor, NULL, 0 ) ) ;
  593. }
  594.  
  595.  
  596. VOID TaskCount::Repaint
  597. (
  598.   HPS hPS,
  599.   RECTL &Rectangle,
  600.   COLOR TextColor,
  601.   COLOR BackColor,
  602.   BOOL Mandatory
  603. )
  604. {
  605.   ULONG Count = NewValue ( ) ;
  606.  
  607.   if ( Mandatory || ( Count != Value ) )
  608.   {
  609.     BYTE Text [100] ;
  610.     sprintf ( (PCHAR)Text, "%lu ", Count ) ;
  611.     Paint ( hPS, Rectangle, TextColor, BackColor, Text, Count ) ;
  612.   }
  613. }
  614.  
  615.  
  616. ULONG DriveFree::NewValue ( void )
  617. {
  618.   if ( Error )
  619.   {
  620.     return ( 0 ) ;
  621.   }
  622.  
  623.   DosError ( FERR_DISABLEHARDERR ) ;
  624.  
  625.   FSALLOCATE Allocation ;
  626.   USHORT Status = DosQueryFSInfo ( DriveNumber, FSIL_ALLOC, (PBYTE)&Allocation, sizeof(Allocation) ) ;
  627.  
  628.   DosError ( FERR_ENABLEHARDERR ) ;
  629.  
  630.   if ( Status )
  631.   {
  632.     Error = TRUE ;
  633.     return ( 0 ) ;
  634.   }
  635.  
  636.   return ( Allocation.cUnitAvail*Allocation.cSectorUnit*Allocation.cbSector ) ;
  637. }
  638.  
  639.  
  640. VOID DriveFree::Repaint
  641. (
  642.   HPS hPS,
  643.   RECTL &Rectangle,
  644.   COLOR TextColor,
  645.   COLOR BackColor,
  646.   BOOL Mandatory
  647. )
  648. {
  649.   ULONG Size = NewValue ( ) ;
  650.  
  651.   if ( Mandatory || ( Size != Value ) )
  652.   {
  653.     BYTE Text [100] ;
  654.  
  655.     if ( Error )
  656.     {
  657.       strcpy ( PCHAR(Text), PCHAR(DriveError->Ptr()) ) ;
  658.     }
  659.     else
  660.     {
  661.       if ( Size < 0x80000 )
  662.     sprintf ( (PCHAR)Text, "%lu", Size ) ;
  663.       else
  664.     sprintf ( (PCHAR)Text, "%lu", (Size+512)/1024 ) ;
  665.  
  666.       {
  667.     PBYTE p1, p2 ;
  668.     BYTE Work[100] ;
  669.  
  670.     p1 = Text ;
  671.     p2 = Work ;
  672.     while ( *p1 )
  673.     {
  674.       *p2 = *p1 ;
  675.       p1 ++ ;
  676.       p2 ++ ;
  677.       if ( *p1 )
  678.       {
  679.         if ( strlen((PCHAR)p1) % 3 == 0 )
  680.         {
  681.           *p2 = CountryInfo.szThousandsSeparator [0] ;
  682.           p2 ++ ;
  683.         }
  684.       }
  685.     }
  686.     *p2 = 0 ;
  687.     strcpy ( (PCHAR)Text, (PCHAR)Work ) ;
  688.       }
  689.  
  690.       Text[strlen(PCHAR(Text))+1] = 0 ;
  691.       if ( Size < 0x80000 )
  692.     Text[strlen((PCHAR)Text)] = ' ' ;
  693.       else
  694.     Text[strlen((PCHAR)Text)] = 'K' ;
  695.     }
  696.  
  697.     Paint ( hPS, Rectangle, TextColor, BackColor, Text, Size ) ;
  698.   }
  699. }
  700.  
  701.  
  702. ULONG TotalFree::NewValue ( void )
  703. {
  704.   ULONG Free = 0 ;
  705.   ULONG Mask = Drives >> 2 ;
  706.  
  707.   for ( int Drive=3; Drive<=26; Drive++ )
  708.   {
  709.     if ( Mask & 1 )
  710.     {
  711.       DosError ( FERR_DISABLEHARDERR ) ;
  712.  
  713.       FSALLOCATE Allocation ;
  714.       USHORT Status = DosQueryFSInfo ( Drive, FSIL_ALLOC, (PBYTE)&Allocation, sizeof(Allocation) ) ;
  715.  
  716.       DosError ( FERR_ENABLEHARDERR ) ;
  717.  
  718.       if ( Status )
  719.       {
  720.     Drives &= ~ ( 1 << (Drive-1) ) ;
  721.       }
  722.       else
  723.       {
  724.     Free += Allocation.cUnitAvail*Allocation.cSectorUnit*Allocation.cbSector ;
  725.       }
  726.     }
  727.     Mask >>= 1 ;
  728.   }
  729.  
  730.   return ( Free ) ;
  731. }
  732.  
  733.  
  734. VOID TotalFree::Repaint
  735. (
  736.   HPS hPS,
  737.   RECTL &Rectangle,
  738.   COLOR TextColor,
  739.   COLOR BackColor,
  740.   BOOL Mandatory
  741. )
  742. {
  743.   ULONG Size = NewValue ( ) ;
  744.  
  745.   if ( Mandatory || ( Size != Value ) )
  746.   {
  747.     BYTE Text [100] ;
  748.  
  749.     if ( Size < 0x80000 )
  750.       sprintf ( (PCHAR)Text, "%lu", Size ) ;
  751.     else
  752.       sprintf ( (PCHAR)Text, "%lu", (Size+512)/1024 ) ;
  753.  
  754.     {
  755.       PBYTE p1, p2 ;
  756.       BYTE Work[100] ;
  757.  
  758.       p1 = Text ;
  759.       p2 = Work ;
  760.       while ( *p1 )
  761.       {
  762.     *p2 = *p1 ;
  763.     p1 ++ ;
  764.     p2 ++ ;
  765.     if ( *p1 )
  766.     {
  767.       if ( strlen((PCHAR)p1) % 3 == 0 )
  768.       {
  769.         *p2 = CountryInfo.szThousandsSeparator [0] ;
  770.         p2 ++ ;
  771.       }
  772.     }
  773.       }
  774.       *p2 = 0 ;
  775.       strcpy ( (PCHAR)Text, (PCHAR)Work ) ;
  776.     }
  777.  
  778.     Text[strlen(PCHAR(Text))+1] = 0 ;
  779.     if ( Size < 0x80000 )
  780.       Text[strlen((PCHAR)Text)] = ' ' ;
  781.     else
  782.       Text[strlen((PCHAR)Text)] = 'K' ;
  783.  
  784.     Paint ( hPS, Rectangle, TextColor, BackColor, Text, Size ) ;
  785.   }
  786. }
  787.